473,513 Members | 2,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Padding problem in Firefox

I use to trust Firefox, but in this case, I don't know what to think. My
test page:

http://gusgus.cn/test/index.html

IE6 does the right thing. The containting <div> is 600px, and within it,
there's one <div> of 400px and another of 200px, laying side by side.
The right <div> has padding on the left and right, to add some space
within the box, but Firefox (0.9.2) seem to confuse paddings as margins.
Here's the right <div> in my CSS:

#right {
float: right;
width: 200px;
overflow: hidden;
background-color: #DDDDFF; /* blue */
text-align: left;
padding: 8px 8px 8px 8px;
}

This box in Firefox is not 200 wide, but 216 (width + padding). It must
be a bug, or my understanding of margins and padding will crumble.

Gustaf
Jul 20 '05 #1
5 28839
Gustaf Liljegren wrote:
I use to trust Firefox, but in this case, I don't know what to think. My
test page:

http://gusgus.cn/test/index.html

IE6 does the right thing. The containting <div> is 600px, and within it,
there's one <div> of 400px and another of 200px, laying side by side.
The right <div> has padding on the left and right, to add some space
within the box, but Firefox (0.9.2) seem to confuse paddings as margins.
Here's the right <div> in my CSS:

#right {
float: right;
width: 200px;
overflow: hidden;
background-color: #DDDDFF; /* blue */
text-align: left;
padding: 8px 8px 8px 8px;
}

This box in Firefox is not 200 wide, but 216 (width + padding). It must
be a bug, or my understanding of margins and padding will crumble.


Firefox is right. IE6 shows it wrong, but only because you are
triggering quirks mode. See
<http://gutfeldt.ch/matthias/articles/doctypeswitch.html> for details on
quirks and standard mode.

And see
<http://msdn.microsoft.com/workshop/author/css/overview/cssenhancements.asp>
for Microsoft's explanation of the differences, particularly
<http://msdn.microsoft.com/library/en-us/dnie60/html/cssenhancements.asp?frame=true#cssenhancements_top ic3>,
"Fix the Box Instead of Thinking Outside It"

If you remove the <?xml version="1.0" encoding="utf-8"?> line, you'll
trigger standard mode in IE6 and it will show the page the same way as
Firefox.
Matthias

Jul 20 '05 #2
Gustaf Liljegren <gu*****@algonet.se> wrote:
I use to trust Firefox, but in this case, I don't know what to think. My
test page:

http://gusgus.cn/test/index.html

IE6 does the right thing. The containting <div> is 600px, and within it,
there's one <div> of 400px and another of 200px, laying side by side.
The right <div> has padding on the left and right, to add some space
within the box, but Firefox (0.9.2) seem to confuse paddings as margins.
Here's the right <div> in my CSS:

#right {
float: right;
width: 200px;
overflow: hidden;
background-color: #DDDDFF; /* blue */
text-align: left;
padding: 8px 8px 8px 8px;
}

This box in Firefox is not 200 wide, but 216 (width + padding). It must
be a bug, or my understanding of margins and padding will crumble.


Width 200px + left padding 8px + right padding 8px = 216px.
FireFox is right.

IE6 would also be right if you triggered Standards mode, at present
you trigger quirks mode and so it emulates the bugs in IE5 and puts
the padding inside the width. IE6 has a big whereby it triggers quirks
mode upon encountering the xml declaration before the doctype. Ditch
that and it will behave like FireFox (and Opera).

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net> <http://steve.pugh.net/>
Jul 20 '05 #3
Gustaf Liljegren wrote:
I use to trust Firefox, but in this case, I don't know what to think. My
test page:

http://gusgus.cn/test/index.html This box in Firefox is not 200 wide, but 216 (width + padding). It must
be a bug, or my understanding of margins and padding will crumble.


No, Firefox is doing it correctly, it should be 216px. As Matthias
already said, you're triggerring quirks mode in IE, which explians why
it's using the buggy, IE5/Win box-model. (See Tantek's box model hack [1]

The problem is that the full width of a box is calculated by:
(L = Left, R = Right, M = Margin, B = Border, P = Padding)

LM + LB + LP + Width + RP + RB + RM

So, your box width's are:

* #container:
LM + LB + LP + Width + RP + RB + RM
0 0 0 600px 0 0 0 = 600px

* #left:
LM + LB + LP + Width + RP + RB + RM
0 + 0 + 0 + 400px + 0 + 0 + 0 = 400px

* #right:
LM + LB + LP + Width + RP + RB + RM
0 + 0 + 8px + 200px + 8px + 0 + 0 = 216px

So, your #left + #right = 616px, which is wider than #container, so
there is no room for Firefox to fit #right where you want it to. The
easiest fix will be to reduce widht of #left and #right by a total of
16px, and everything should fit nicely. it works best if you set:

#right { width: 384px }
[1] http://www.tantek.com/CSS/Examples/boxmodelhack.html

--
Lachlan Hunt
http://www.lachy.id.au/

Please direct all spam to ab***@127.0.0.1
Thank you.
Jul 20 '05 #4
On Mon, 09 Aug 2004 16:20:03 +0200, Gustaf Liljegren
<gu*****@algonet.se> wrote:
http://gusgus.cn/test/index.html

IE6 does the right thing...
No it's not, provided that I have understood your question correct.
Here's the right <div> in my CSS:

#right {
float: right;
width: 200px;
overflow: hidden;
background-color: #DDDDFF; /* blue */
text-align: left;
padding: 8px 8px 8px 8px;
}

This box in Firefox is not 200 wide, but 216...
...a bug, or my understanding of margins and padding
will crumble.


The total outside width of a <div> box is the sum of the values for the
following properties...

margin-left
+ border-left-width
+ padding-left
+ width
+ padding-right
+ border-right-width
+ margin-right
= total occupied width of any {display:block} type box

So your "understanding of margins and padding" needs to be updated :-)

Most especially; the 'width' property suggests a width for the box
content only, all the other properties are added on the outside of that
inner content width.

<http://www.w3.org/TR/CSS1#block-level-elements>

--
Rex
Jul 20 '05 #5
Thanks a lot to everyone who help me with this question. Now I
understand what widths and heights really are.

But I can't help thinking IE had a good idea. The standard compliant way
means that everytime you use a little border or padding, you also need
to subtract the same amounts from the widths and heights = more fiddling
before you get it right.

Anyway, I'm glad to understand now.

Gustaf
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6742
by: StarQuake | last post by:
At this site: http://forwarding.robas.com You can see in IE there is cell padding in 'Berkman Bedrijven' and with Firefox there isn't. I don't want any cell padding. Anyone? --...
1
3043
by: books1999 | last post by:
Hi there, I have a problem with this css/div and i cannot work it out. I would like either container to be able to push the background box to grow but in Firefox it overflows. Can someone find a...
36
2984
by: phil-news-nospam | last post by:
Here is a simpler (no drop shadows) example of the padding bug I see: http://phil.ipal.org/usenet/ciwas/2006-05-08/buttons-1.html So far I find nothing in the CSS2 document that says I should...
2
17071
by: cbjewelz | last post by:
Hey all. So I'm having problems with cross browser alignments. I'm looking at Safari and Mozilla Firefox. I develop in Safari and so it looks perfect there however in Firefox my vertical...
3
5598
by: autospanker | last post by:
Ladies and Gentleman, I have been having this problem that has been driving me insane. I have a website that when viewed in Firefox first, the content in the body area is pushed down. Then when...
0
1610
by: Bouzy | last post by:
I have a problem that I know gets asked about a lot. Its how my page differs in IE vrs. Firefox. I know IE sucks, but hears whats going on. IE......
2
2633
by: pammyspammy | last post by:
Hi - Some background info: I'm helping to redesign an internal website at work, and I've decided to use CSS, though I don't really have any experience with it. I figure now's a good time to...
1
4183
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
3
2004
by: Steve | last post by:
Hi All I have an asp.net 2.0 website with the following css file It uses Master pages and in Firefox 3.04 for windows only, 3 of the web pages don't display the Master page properly The...
0
7559
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7123
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4756
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3248
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3237
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.